import subprocess
import sys
import time
from concurrent.futures.thread import ThreadPoolExecutor


python_path = sys.executable
run_path = r"G:\pytest\django\djangoProject08\framework\main_django.py"  # 框架的路径
case_path = (
    r"G:\pytest\django\djangoProject08\framework\tests\test_case.py"  # 寻找yaml文件
)



def run_pytst(path,result_id=1):   # 修改 增加了参数 result_id
    print("开始执行进程执行框架", time.time())
    process = subprocess.run(
        f"{python_path} {run_path} {case_path} result_id {result_id}",
        cwd=path,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
    )  # 创建子进程
    try:
        print(process.stdout.decode("utf-8"))
        print(process.stderr.decode("utf-8"))
    except UnicodeDecodeError:
        print(process.stdout.decode("gbk"))
        print(process.stderr.decode("gbk"))

if __name__ == '__main__':

    pool = ThreadPoolExecutor(max_workers=6)
    # 对 pool.map 的结果进行迭代，确保任务被执行
    test_path = r"G:\pytest\django\zsdx\xxxx"
    results = list(pool.map(run_pytst, test_path))
    pool.shutdown()